package com.vic.stock;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 计算股票相关数值
 */
public class StockTest {

    public static void main(String[] args) {

        // 今日价格
        BigDecimal todayPr = new BigDecimal("14.64");
        // 昨日价格
        BigDecimal yesterdayPr = new BigDecimal("13.31");

        // 股数
        BigDecimal stockAmt = new BigDecimal("500");

        BigDecimal upDownPr = todayPr.subtract(yesterdayPr);
        System.out.println("涨跌值：" + upDownPr);
        System.out.println("涨跌幅：" + upDownPr.divide(yesterdayPr, 4, RoundingMode.HALF_UP));

        BigDecimal todayTotalMarketValue = todayPr.multiply(stockAmt);
        System.out.println("当前市值：" + todayTotalMarketValue);

        // 昨日市值
        BigDecimal yesterdayTotalMarketValue = yesterdayPr.multiply(stockAmt);
        System.out.println("昨日市值：" + yesterdayTotalMarketValue);

        // 今日增加市值
        BigDecimal totalAddMarketValue = todayTotalMarketValue.subtract(yesterdayTotalMarketValue);
        System.out.println("今日增加市值：" + totalAddMarketValue);

        // 市值涨跌幅
        BigDecimal marketValueRate = totalAddMarketValue.divide(yesterdayTotalMarketValue, 4, RoundingMode.HALF_UP);
        System.out.println("市值涨跌幅：" + marketValueRate);

    }
}
